using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Data.Models.Mapping
{
    public class PurchaseMap : EntityTypeConfiguration<Purchase>
    {
        public PurchaseMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.Code)
                .HasMaxLength(40);

            this.Property(t => t.Note)
                .HasMaxLength(1000);

            this.Property(t => t.Attactment)
                .HasMaxLength(250);

            this.Property(t => t.ContactName)
                .HasMaxLength(255);

            this.Property(t => t.ContactAddress)
                .HasMaxLength(250);

            // Table & Column Mappings
            this.ToTable("Purchases");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.Code).HasColumnName("Code");
            this.Property(t => t.Note).HasColumnName("Note");
            this.Property(t => t.Attactment).HasColumnName("Attactment");
            this.Property(t => t.CreatedDate).HasColumnName("CreatedDate");
            this.Property(t => t.CreatedUserID).HasColumnName("CreatedUserID");
            this.Property(t => t.ApprovalUserID).HasColumnName("ApprovalUserID");
            this.Property(t => t.DueDate).HasColumnName("DueDate");
            this.Property(t => t.ContactID).HasColumnName("ContactID");
            this.Property(t => t.ContactName).HasColumnName("ContactName");
            this.Property(t => t.Discount).HasColumnName("Discount");
            this.Property(t => t.SubTotal).HasColumnName("SubTotal");
            this.Property(t => t.Tax).HasColumnName("Tax");
            this.Property(t => t.TotalMoney).HasColumnName("TotalMoney");
            this.Property(t => t.Status).HasColumnName("Status");
            this.Property(t => t.UseVAT).HasColumnName("UseVAT");
            this.Property(t => t.StockID).HasColumnName("StockID");
            this.Property(t => t.ApprovalDate).HasColumnName("ApprovalDate");
            this.Property(t => t.CompanyID).HasColumnName("CompanyID");
            this.Property(t => t.ContactAddress).HasColumnName("ContactAddress");
            this.Property(t => t.CurrencyID).HasColumnName("CurrencyID");

            // Relationships
            this.HasOptional(t => t.Company)
                .WithMany(t => t.Purchases)
                .HasForeignKey(d => d.CompanyID);
            this.HasOptional(t => t.Contact)
                .WithMany(t => t.Purchases)
                .HasForeignKey(d => d.ContactID);
            this.HasOptional(t => t.Currency)
                .WithMany(t => t.Purchases)
                .HasForeignKey(d => d.CurrencyID);
            this.HasOptional(t => t.Employee)
                .WithMany(t => t.Purchases)
                .HasForeignKey(d => d.CreatedUserID);
            this.HasOptional(t => t.Employee1)
                .WithMany(t => t.Purchases1)
                .HasForeignKey(d => d.ApprovalUserID);
            this.HasOptional(t => t.Stock)
                .WithMany(t => t.Purchases)
                .HasForeignKey(d => d.StockID);
            this.HasOptional(t => t.User)
                .WithMany(t => t.Purchases)
                .HasForeignKey(d => d.ApprovalUserID);
            this.HasOptional(t => t.User1)
                .WithMany(t => t.Purchases1)
                .HasForeignKey(d => d.CreatedUserID);

        }
    }
}
